import { Space, message, Tooltip } from "antd";
import { QuestionCircleOutlined } from "@ant-design/icons";
import SelectActions from "@/views/components/SelectActions";
import IconFont from "@/components/IconFont";
import { DialogEnum } from "../Actions";
import { totalInventoryList } from "../../service";
export const LeftBtns = ({
	addList,
	setAddList,
	dataSource,
	selectedRows,
	updateDataSource,
	setActionName,
	setActionsProps,
	onCancel
}) => {
	return (
		<Space className="views-action-left" style={{ height: 28 }}>
			<SelectActions
				type="primary"
				overlayClassName="SelectActions"
				name={<span style={{ lineHeight: "19px" }}>新增商品</span>}
				onClick={() => {
					setActionsProps({
						handleCancel() {
							onCancel();
						},
						async onGoodsSkuListSelected(values) {
							console.log("onGoodsSkuListSelected", values);
							const res = await totalInventoryList({ skuIdList: values.map(e => e.id).join(",") });
							const { success, data } = res;
							if (success) {
								const list = values.map(item => {
									const { esInventory } = data.find(e => e.skuId === item.id);
									return {
										...item,
										supplierId: null,
										supplierName: null,
										areaCode: null,
										areaName: null,
										skuId: item.id,
										skuImage: item.image,
										skuName: item.skuName,
										skuSpec: item.specs,
										skuCode: item.skuCode,
										spuCode: item.spuCode,
										skuPrice: item.purchasePrice,
										suggestNum: null, //原建议采购数
										actualNum: item.num, //实际采购数
										warehouseMap: esInventory
									};
								});
								setAddList([...list]);
								message.success("操作成功");
								onCancel();
							}
						},
						selectTitle: <>选择商品（申请会员价仅支持精准匹配的商品）</>,
						destroyOnClose: true
					});
					setActionName(DialogEnum.GoodsList);
				}}
			/>
			<SelectActions
				overlayClassName="SelectActions"
				name={<span style={{ lineHeight: "18px" }}>批量修改数量</span>}
				onClick={() => {
					if (selectedRows.length === 0) return message.warning("没有可操作的数据，请重新勾选");
					setActionsProps({ selectedRows, updateDataSource, dataSource });
					setActionName(DialogEnum.BatchModifyQuantity);
				}}
			/>
		</Space>
	);
};
export const RightBtns = ({ setActionName }) => {
	return (
		<Space>
			<SelectActions
				overlayClassName="SelectActions"
				type="text"
				// name={<span style={{ lineHeight: "21px" }}>采购规则设置</span>}
				onClick={() => {
					setActionName(DialogEnum.RuleSettings);
				}}
			>
				<IconFont type="iconguizeshezhi" style={{ fontSize: 16 }} />
				<span className="line-height-21" style={{ display: "inline-block" }}>
					采购规则设置
				</span>
			</SelectActions>
		</Space>
	);
};
